﻿Public Class informeCVentas
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCamcela.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsulta.Click
        ''Valido la fecha
        If ValidaFecha(dtpFecDesde.Value, dtpFecHasta.Value) = False Then
            Exit Sub
        End If


        Dim VentasBusiness As New businessVentas()
        Dim ListaVentas As New List(Of clsVentas)
        Dim Cod_Suc As Int32
        Dim Vta_Id As Int32
        Dim Cli_Id As Int32
        Dim ImporteDesde As Decimal
        Dim ImporteHasta As Decimal
        Dim FecDesde As Date
        Dim FecHasta As Date


        Try
            ''Vta_id
            If txtNroVenta.Text.Trim.Length > 0 Then
                Vta_Id = Convert.ToInt32(txtNroVenta.Text.Trim)
            Else
                Vta_Id = 0
            End If

            'Cli_id
            If txtNroCliente.Text.Trim.Length > 0 Then
                Cli_Id = Convert.ToInt32(txtNroCliente.Text.Trim)
            Else
                Cli_Id = 0
            End If

            If txtImporteDesde.Text.Trim.Length > 0 Then
                ImporteDesde = Convert.ToDecimal(txtImporteDesde.Text.Trim)
            Else
                ImporteDesde = 0
            End If

            If txtImporteHasta.Text.Trim.Length > 0 Then
                ImporteHasta = Convert.ToDecimal(txtImporteHasta.Text.Trim)
            Else
                ImporteHasta = 0
            End If
            If ImporteDesde > ImporteHasta Then
                MessageBox.Show("El importe Desde no puede ser Mayor al Importe Hasta", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If

            FecDesde = dtpFecDesde.Value
            FecHasta = dtpFecHasta.Value

            Select Case cmbSucursal.Text
                Case "SUCURSAL 1"
                    Cod_Suc = 1
                Case "SUCURSAL 2"
                    Cod_Suc = 2
                Case "CASA CENTRAL"
                    Cod_Suc = 3
            End Select

            ListaVentas = VentasBusiness.ConsultaVentas(Vta_Id, Cli_Id, ImporteDesde, ImporteHasta, FecDesde, FecHasta, Cod_Suc)

            If ListaVentas.Count > 0 Then
                TraeConsulta(ListaVentas)
            Else
                MessageBox.Show("No hay datos para mostrar con los parametros ingresados", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
        End Try
    End Sub

    Private Sub txtSucursal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        validarInt(e)
    End Sub

    Private Sub txtCodArticulo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        validarInt(e)
    End Sub

    Private Sub txtImporteInicial_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtImporteDesde.KeyPress
        validarDouble(e)
    End Sub

    Private Sub txtImporteMaximo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtImporteHasta.KeyPress
        validarDouble(e)
    End Sub

    Private Sub informeCVentas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LimpiaForm()
    End Sub
    Private Sub LimpiaForm()
        txtNroVenta.Text = ""
        txtNroCliente.Text = ""
        txtImporteDesde.Text = ""
        txtImporteHasta.Text = ""
        dtpFecDesde.Value = Now.Date
        dtpFecHasta.Value = Now.Date
        cmbSucursal.SelectedIndex = 0
        dtpFecDesde.MaxDate = Now.Date
        dtpFecHasta.MaxDate = Now.Date

    End Sub

    Private Sub btnLimpiaForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiaForm.Click
        LimpiaForm()
    End Sub
    Private Sub TraeConsulta(ByVal ListaVentas As List(Of clsVentas))
        Me.Enabled = False
        consultaVentas.ModoAcceso = "IINFORME VTA"
        consultaVentas.FormatoGrilla()
        consultaVentas.CargaGrilla(ListaVentas)
        consultaVentas.MdiParent = Me.MdiParent
        consultaVentas.Show()
    End Sub

End Class